package com.oa.modules.approvalsec1.controller;

import com.alibaba.fastjson.JSON;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.oa.common.utils.*;
import com.oa.modules.approvalsec1.entity.CompletAccept;
import com.oa.modules.approvalsec1.entity.TeacherQualificationEntity;
import com.oa.modules.approvalsec1.service.TeacherQualificationService;
import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Array;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.zip.ZipOutputStream;


/**
 * 教师资格证认定
 */
@RestController
@RequestMapping("teacher/qualification")
@Api(tags = "教师资格认定相关接口")
public class TeacherQualificationController extends AbstractController {

    @Value("${url.saveUrl}")
    private String zipFilePath;

    private static final Logger log = LoggerFactory.getLogger(TeacherQualificationController.class);
    @Autowired
    private TeacherQualificationService teacherQualificationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R list(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        PageUtils page = teacherQualificationService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 类型列表
     */
    @GetMapping("/typeList/{createOper}")
    @ApiOperation(value = "教资认定类型列表")
    public R typeList(@PathVariable("createOper") String createOper) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        map1.put("type", "1");
        map1.put("typeName", "幼儿园教师资格认定");
        map2.put("type", "2");
        map2.put("typeName", "小学教师资格认定");
        map3.put("type", "3");
        map3.put("typeName", "初级中学教师资格认定");
        //处理创建者为空、null、undefined
        if(!"".equals(createOper) && createOper != null && !"undefined".equals(createOper)){
            List<TeacherQualificationEntity> tList = teacherQualificationService.queryByUser(createOper);
            if (tList.size() > 0) {
                for (TeacherQualificationEntity t : tList) {
                    if (t.getType() == 1) {
                        map1.put("status", t.getStatus());
                    }
                    if (t.getType() == 2) {
                        map2.put("status", t.getStatus());
                    }
                    if (t.getType() == 3) {
                        map3.put("status", t.getStatus());
                    }
                }
            }
        }
        list.add(map1);
        list.add(map2);
        list.add(map3);
        return R.ok().put("list", list);
    }

    /**
     * 类型列表
     */
    @GetMapping("/aTypeList")
    @ApiOperation(value = "教资认定类型列表")
    public R aTypeList(@RequestParam("createOper") String createOper) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        map1.put("type", "1");
        map1.put("typeName", "幼儿园教师资格认定");
        map2.put("type", "2");
        map2.put("typeName", "小学教师资格认定");
        map3.put("type", "3");
        map3.put("typeName", "初级中学教师资格认定");
        //处理创建者为空、null、undefined
        if(!"".equals(createOper) && createOper != null && !"undefined".equals(createOper)){
            List<TeacherQualificationEntity> tList = teacherQualificationService.queryByUser(createOper);
            if (tList.size() > 0) {
                for (TeacherQualificationEntity t : tList) {
                    if (t.getType() == 1) {
                        map1.put("status", t.getStatus());
                    }
                    if (t.getType() == 2) {
                        map2.put("status", t.getStatus());
                    }
                    if (t.getType() == 3) {
                        map3.put("status", t.getStatus());
                    }
                }
            }
        }
        list.add(map1);
        list.add(map2);
        list.add(map3);
        return R.ok().put("list", list);
    }


    @GetMapping("/typeList")
    @ApiOperation(value = "教资认定类型列表")
    public R typeList() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        map1.put("type", "1");
        map1.put("typeName", "幼儿园教师资格认定");
        map2.put("type", "2");
        map2.put("typeName", "小学教师资格认定");
        map3.put("type", "3");
        map3.put("typeName", "初级中学教师资格认定");
        list.add(map1);
        list.add(map2);
        list.add(map3);

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") String id) {
        TeacherQualificationEntity teacherQualification = teacherQualificationService.getById(id);

        return R.ok().put("teacherQualification", teacherQualification);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody TeacherQualificationEntity teacherQualification) {
        String createOper = teacherQualification.getCreateOper();
        if(!"".equals(createOper) && createOper != null && !"undefined".equals(createOper) && !"null".equals(createOper)){
            //log.info("save接口接收参数 ==》 "+teacherQualification);
            //校验是否已存在此用户此类型教师资格认定申请
            TeacherQualificationEntity t = teacherQualificationService.selectTeacherQualificationEntity(teacherQualification);
            if (t == null) {
                //不存在，新增保存
                teacherQualification.setId(AppUtils.getUUID());
                teacherQualification.setCreateDate(new Date());
                //teacherQualification.setCreateOper("1");
                teacherQualification.setStatus(0);
                teacherQualificationService.save(teacherQualification);
            } else {
                //存在，更新提交数据
                if(t.getStatus()==2){
                    //驳回再提交状态改为 待审核
                    teacherQualification.setStatus(0);
                }else{
                    teacherQualification.setStatus(t.getStatus());
                }
                teacherQualification.setId(t.getId());
                //log.info("tttt>>>"+teacherQualification);
                teacherQualificationService.saveOther(teacherQualification);
            }

            return R.ok();
        }else{
            return R.error("请回到小程序首页进行登录操作");
        }

    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody TeacherQualificationEntity teacherQualification) {
        //teacherQualification.setUpdateDate(new Date());
        //teacherQualification.setUpdateOper("1");
        //teacherQualificationService.updateById(teacherQualification);
        teacherQualificationService.updateByIdx(teacherQualification);
        return R.ok();
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@RequestBody String[] ids) {
        teacherQualificationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 通过用户ID(createOper)和类型(type)删除
     */
    @PostMapping("/deleteByUserAndType")
    @ApiOperation(value = "通过用户ID(createOper)和类型(type)删除")
    public R deleteByUserAndType(@RequestBody TeacherQualificationEntity teacherQualification) {
        String createOper = teacherQualification.getCreateOper();
        if(!"".equals(createOper) && createOper != null && !"undefined".equals(createOper)){
            teacherQualificationService.deleteByUserAndType(teacherQualification);
            return R.ok();
        }else {
            return R.error("请回到小程序首页进行登录操作");
        }


    }

    /**
     * 通过用户ID(createOper)和类型(type)查询
     */
    @PostMapping("/queryByUserAndType")
    @ApiOperation(value = "通过用户ID(createOper)和类型(type)查询")
    public R queryByUserAndType(@RequestBody TeacherQualificationEntity teacherQualification) throws IllegalAccessException {
        String createOper = teacherQualification.getCreateOper();
        TeacherQualificationEntity teacherQualificationEntity = null;
        if(!"".equals(createOper) && createOper != null && !"undefined".equals(createOper)){
            teacherQualificationEntity = teacherQualificationService.selectTeacherQualificationEntity(teacherQualification);
        }
        //TeacherQualificationEntity teacherQualificationEntity = teacherQualificationService.selectTeacherQualificationEntity(teacherQualification);
        //TeacherQualificationEntity teacherQualificationEntity1 = CommonUtils.setNullValue(teacherQualificationEntity);
        return R.ok().put("teacherQualification", teacherQualificationEntity);
    }


    /**
     * 通过用户ID(createOper)查询
     */
    @GetMapping("/queryByUser/{createOper}")
    @ApiOperation(value = "通过用户ID(createOper)查询")
    public R queryByUser(@PathVariable("createOper") String createOper) {
        List<TeacherQualificationEntity> list = null;
        if(!"".equals(createOper) && createOper != null && !"undefined".equals(createOper)){
            list = teacherQualificationService.queryByUser(createOper);
        }
        //List<TeacherQualificationEntity> list = teacherQualificationService.queryByUser(createOper);
        return R.ok().put("list", list);
    }


    /**
     * 办结
     */
    @PostMapping("/settle")
    @ApiOperation(value = "审核通过")
    public R settle(@RequestParam String id) {
        teacherQualificationService.settle(id);
        return R.ok();
    }

    /**
     * 办结
     */
    @PostMapping("/yushen")
    @ApiOperation(value = "预审通过")
    public R yushen(@RequestParam String id) {
        teacherQualificationService.yushen(id);
        return R.ok();
    }

    /**
     * 驳回
     */
    @PostMapping("/reject")
    @ApiOperation(value = "驳回")
    public R reject(@RequestBody Map<String, Object> map) {
        //log.info("reject接口接收参数 ==》 "+map);
        teacherQualificationService.reject(map);
        return R.ok();
    }


    @PostMapping(value = "/export")
    @ApiOperation(value = "导出审核通过邮寄信息")
    public void export(@RequestBody TeacherQualificationEntity teacherQualification, HttpServletResponse response) throws IOException {
        List<TeacherQualificationEntity> records = teacherQualificationService.queryAllAdopt(teacherQualification);
        HSSFWorkbook wb = donloadExcel(records);
        OutputStream output = response.getOutputStream();

        String fileName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()).toString()+".xls";//
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-disposition", "attachment;filename="+fileName+";"+"filename*=utf-8''"+fileName);
        wb.write(output);
        output.close();

    }



    @GetMapping("/zipDownload/{id}")
    @ApiOperation(value = "文件打包下载")
    public void zipDownload(@PathVariable("id") String id, HttpServletResponse response) {
        //log.info("zipDownload接口接收参数 ==》 "+id);
        // String zipFilePath = "/home/zipTemp/";
        TeacherQualificationEntity t = teacherQualificationService.getById(id);
        //log.info("查询结果==》 "+t);
        //创建集合存储路径
        ArrayList<Map<String, String>> pathList2 = new ArrayList<Map<String, String>>();
        //基本信息
        String pdfPath = "";
        if (t != null && !"".equals(t)) {
            Map<String, String> map = new HashMap<>();
            String path = createPDF(t,zipFilePath);
            pdfPath = path;
            String realFileName = "教师资格认定基本信息.pdf";
            map.put("realFileName", realFileName);
            map.put("path", path);
            pathList2.add(map);
        }


        //证件照
        String idPhoto = t.getIdPhoto();
        if (!"".equals(idPhoto) && idPhoto != null) {
            String[] idPhotos = idPhoto.split(",");
            for (int i = 0; i < idPhotos.length; i++) {
                Map<String, String> map = new HashMap<>();
                //真实的文件名
                String realFileName = "证件照片" + (i + 1);
                //文件路径
                String path = idPhotos[i];
                //获取真实路径
                String realPath = getRealPath(path);
                //获取文件后缀
                String suffix = path.substring(path.lastIndexOf("."), path.length());
                map.put("realFileName", realFileName + suffix);
                map.put("path", realPath);
                pathList2.add(map);
            }
        }
        //户籍证明
        String registeredResidence = t.getRegisteredResidence();
        if (!"".equals(registeredResidence) && registeredResidence != null) {
            String[] registeredResidences = registeredResidence.split(",");
            for (int i = 0; i < registeredResidences.length; i++) {
                Map<String, String> map = new HashMap<>();
                //真实的文件名
                String realFileName = "户籍证明" + (i + 1);
                //文件路径
                String path = registeredResidences[i];
                //获取真实路径
                String realPath = getRealPath(path);
                //获取文件后缀
                String suffix = path.substring(path.lastIndexOf("."), path.length());
                map.put("realFileName", realFileName + suffix);
                map.put("path", realPath);
                pathList2.add(map);
            }
        }
        //体检表
        String medicalReport = t.getMedicalReport();
        if (!"".equals(medicalReport) && medicalReport != null) {
            String[] medicalReports = medicalReport.split(",");
            for (int i = 0; i < medicalReports.length; i++) {
                Map<String, String> map = new HashMap<>();
                //真实的文件名
                String realFileName = "体检报告" + (i + 1);
                //文件路径
                String path = medicalReports[i];
                //获取真实路径
                String realPath = getRealPath(path);
                //获取文件后缀
                String suffix = path.substring(path.lastIndexOf("."), path.length());
                map.put("realFileName", realFileName + suffix);
                map.put("path", realPath);
                pathList2.add(map);
            }
        }
        //学历证明
        String academicCertificate = t.getAcademicCertificate();
        if (!"".equals(academicCertificate) && academicCertificate != null) {
            String[] academicCertificates = academicCertificate.split(",");
            for (int i = 0; i < academicCertificates.length; i++) {
                Map<String, String> map = new HashMap<>();
                //真实的文件名
                String realFileName = "学历证明" + (i + 1);
                //文件路径
                String path = academicCertificates[i];
                //获取真实路径
                String realPath = getRealPath(path);
                //获取文件后缀
                String suffix = path.substring(path.lastIndexOf("."), path.length());
                map.put("realFileName", realFileName + suffix);
                map.put("path", realPath);
                pathList2.add(map);
            }
        }
        //普通话证书
        String mandarinCertificate = t.getMandarinCertificate();
        if (!"".equals(mandarinCertificate) && mandarinCertificate != null) {
            String[] mandarinCertificates = mandarinCertificate.split(",");
            for (int i = 0; i < mandarinCertificates.length; i++) {
                Map<String, String> map = new HashMap<>();
                //真实的文件名
                String realFileName = "普通话证书" + (i + 1);
                //文件路径
                String path = mandarinCertificates[i];
                //获取真实路径
                String realPath = getRealPath(path);
                //获取文件后缀
                String suffix = path.substring(path.lastIndexOf("."), path.length());
                map.put("realFileName", realFileName + suffix);
                map.put("path", realPath);
                pathList2.add(map);
            }
        }
        //身份证照片
        String professionalCertificate = t.getProfessionalCertificate();
        if (!"".equals(professionalCertificate) && professionalCertificate != null) {
            String[] professionalCertificates = professionalCertificate.split(",");
            for (int i = 0; i < professionalCertificates.length; i++) {
                Map<String, String> map = new HashMap<>();
                //真实的文件名
                String realFileName = "免试认定书" + (i + 1);
                //文件路径
                String path = professionalCertificates[i];
                //获取真实路径
                String realPath = getRealPath(path);
                //获取文件后缀
                String suffix = path.substring(path.lastIndexOf("."), path.length());
                map.put("realFileName", realFileName + suffix);
                map.put("path", realPath);
                pathList2.add(map);
            }
        }

       // log.info("路径集合==》 " + pathList2);
        String packageName = t.getSignNumber() + ".zip";
        //判断集合是否有路径
        if (pathList2.size() != 0) {
            // 压缩输出流,包装流,将临时文件输出流包装成压缩流,将所有文件输出到这里,打成zip包
            ZipOutputStream zipOut = null;
            try {
                zipOut = new ZipOutputStream(new FileOutputStream(zipFilePath + packageName));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            // 循环调用压缩文件方法,将一个一个需要下载的文件打入压缩文件包
            for (Map<String, String> map : pathList2) {
                String path = map.get("path");

                int lastIndexOf = path.lastIndexOf("/") + 1;
                String realFileName = map.get("realFileName");

                String realPath = path;
                try {
                    //调用工具类方法,传递路径和压缩流，压缩包文件的名字
                    DownLoadZipUtil.fileToZip(realPath, zipOut, realFileName);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            try {
                // 压缩完成后,关闭压缩流
                zipOut.close();
            } catch (IOException e) {
                e.printStackTrace();
            }


            //提高作用域
            String fileName = null;
            try {
                //下载名称并转为ISO-8859-1格式，解决中文乱码
                fileName = new String(packageName.getBytes("UTF-8"), "ISO8859-1");
                //设置内容内容型应用下载，设置字符集
                response.setContentType("application/x-download;charset=utf-8");
                //告诉客户端该文件不是直接解析而是以附件的形式打开（下载）
                response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            //提高作用域
            ServletOutputStream outputStream = null;
            FileInputStream inputStream = null;
            try {
                //该流不可以手动关闭,手动关闭下载会出问题,下载完成后会自动关闭
                outputStream = response.getOutputStream();
                inputStream = new FileInputStream(zipFilePath + packageName);
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                //文件下载，复制
                IOUtils.copy(inputStream, outputStream);
            } catch (IOException e) {
                e.printStackTrace();
            }

            // 关闭输入流
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            //下载完成，删掉zip包
            File fileTempZip = new File(zipFilePath + packageName);
            fileTempZip.delete();
            //删除pdf
            File pdfFile = new File(pdfPath);
            pdfFile.delete();

        }


    }


    public static String getRealPath(String path) {
        String realPath = path;
        if (path.indexOf("https://www.qhspj.com/") != -1) {
            //不是绝对路径
            String sb = path.substring(path.lastIndexOf(".") + 1, path.length());
            if ("GIF".equals(sb.toUpperCase()) || "PNG".equals(sb.toUpperCase()) || "JPG".equals(sb.toUpperCase()) || "TIF".equals(sb.toUpperCase()) || "JPEG".equals(sb.toUpperCase())) {
                realPath = path.replaceAll("https://www.qhspj.com/", "/home/image");
            } else {
                realPath = path.replaceAll("https://www.qhspj.com/", "/home/file");
            }
        }

        return realPath;

    }


    public static String createPDF(TeacherQualificationEntity teacherQualification,String savePath) {
        Map<String, Object> map = new HashMap<String, Object>();
        //log.info("路径===》"+savePath);
        File filePdfPath = new File(savePath);
        if (!filePdfPath.exists()) {
            filePdfPath.mkdirs();
        }
        String tempName = teacherQualification.getSignNumber() + "教师资格认定基本信息.pdf";
        String tempFileName = savePath + tempName;
        try {
            Font font = CreatePDFUtil.getFont("黑体");
            font.setSize(15);
            Font font1 = CreatePDFUtil.getFont("黑体");
            font1.setSize(12);
            Font font2 = CreatePDFUtil.getFont("Arial");
            font2.setSize(12);
            Rectangle one = new Rectangle(820, 650);
            Document document = new Document(one, 0, 0, 5, 0);

            FileOutputStream writer = new FileOutputStream(tempFileName);
            PdfWriter.getInstance(document, writer);

            document.open();


            document.newPage();

            //创建table
            PdfPTable table = new PdfPTable(3);
            table.setTotalWidth(800);
            table.setLockedWidth(true);

            PdfPCell cellBaseInfo = new PdfPCell();
            cellBaseInfo.setPhrase(new Phrase("个人详细信息", font));
            cellBaseInfo.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellBaseInfo.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellBaseInfo.setFixedHeight(55);
            cellBaseInfo.setColspan(3);

            PdfPCell cellName = new PdfPCell();
            cellName.setPhrase(new Phrase("姓名", font1));
            cellName.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellName.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellName.setFixedHeight(55);

            PdfPCell cellNameValue = new PdfPCell();
            cellNameValue.setPhrase(new Phrase(teacherQualification.getName(), font1));
            cellNameValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellNameValue.setFixedHeight(55);
            cellNameValue.setColspan(2);//合并单元格

            PdfPCell cellIdCard = new PdfPCell();
            cellIdCard.setPhrase(new Phrase("身份证号", font1));
            cellIdCard.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellIdCard.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellIdCard.setFixedHeight(55);

            PdfPCell cellIdCardValue = new PdfPCell();
            cellIdCardValue.setPhrase(new Phrase(teacherQualification.getIdCard(), font1));
            cellIdCardValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellIdCardValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellIdCardValue.setFixedHeight(55);
            cellIdCardValue.setColspan(2);//合并单元格

            PdfPCell cellSignNumber = new PdfPCell();
            cellSignNumber.setPhrase(new Phrase("报名号", font1));
            cellSignNumber.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellSignNumber.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellSignNumber.setFixedHeight(55);

            PdfPCell cellSignNumberValue = new PdfPCell();
            cellSignNumberValue.setPhrase(new Phrase(teacherQualification.getSignNumber(), font1));
            cellSignNumberValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellSignNumberValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellSignNumberValue.setFixedHeight(55);
            cellSignNumberValue.setColspan(2);//合并单元格


            PdfPCell cellType = new PdfPCell();
            cellType.setPhrase(new Phrase("认定类型", font1));
            cellType.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellType.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellType.setFixedHeight(55);

            String rdlx = "";
            if (teacherQualification.getType() == 1) {
                rdlx = "幼儿园教师资格证认定";
            }
            if (teacherQualification.getType() == 2) {
                rdlx = "小学教师资格证认定";
            }
            if (teacherQualification.getType() == 3) {
                rdlx = "初级中学教师资格证认定";
            }
            PdfPCell cellTypeValue = new PdfPCell();
            cellTypeValue.setPhrase(new Phrase(rdlx, font1));
            cellTypeValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTypeValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTypeValue.setFixedHeight(55);
            cellTypeValue.setColspan(2);//合并单元格


            PdfPCell cellMailInfo = new PdfPCell();
            cellMailInfo.setPhrase(new Phrase("邮寄详细信息", font));
            cellMailInfo.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailInfo.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailInfo.setFixedHeight(55);
            cellMailInfo.setColspan(3);

            PdfPCell cellMailName = new PdfPCell();
            cellMailName.setPhrase(new Phrase("姓名", font1));
            cellMailName.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailName.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailName.setFixedHeight(55);

            PdfPCell cellMailNameValue = new PdfPCell();
            cellMailNameValue.setPhrase(new Phrase(teacherQualification.getMailName(), font1));
            cellMailNameValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailNameValue.setFixedHeight(55);
            cellMailNameValue.setColspan(2);

            PdfPCell cellMailIdCard = new PdfPCell();
            cellMailIdCard.setPhrase(new Phrase("身份证号", font1));
            cellMailIdCard.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailIdCard.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailIdCard.setFixedHeight(55);

            PdfPCell cellMailIdCardValue = new PdfPCell();
            cellMailIdCardValue.setPhrase(new Phrase(teacherQualification.getMailIdcard(), font1));
            cellMailIdCardValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailIdCardValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailIdCardValue.setFixedHeight(55);
            cellMailIdCardValue.setColspan(2);

            PdfPCell cellMailPhone = new PdfPCell();
            cellMailPhone.setPhrase(new Phrase("手机号", font1));
            cellMailPhone.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailPhone.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailPhone.setFixedHeight(55);

            PdfPCell cellMailPhoneValue = new PdfPCell();
            cellMailPhoneValue.setPhrase(new Phrase(teacherQualification.getMailPhone(), font1));
            cellMailPhoneValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailPhoneValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailPhoneValue.setFixedHeight(55);
            cellMailPhoneValue.setColspan(2);


            PdfPCell cellMailAddress = new PdfPCell();
            cellMailAddress.setPhrase(new Phrase("地址", font1));
            cellMailAddress.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailAddress.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailAddress.setFixedHeight(55);

            PdfPCell cellMailAddressValue = new PdfPCell();
            cellMailAddressValue.setPhrase(new Phrase(teacherQualification.getMailAddress(), font1));
            cellMailAddressValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailAddressValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailAddressValue.setFixedHeight(55);
            cellMailAddressValue.setColspan(2);

            PdfPCell cellMailAddressDetail = new PdfPCell();
            cellMailAddressDetail.setPhrase(new Phrase("详细地址", font1));
            cellMailAddressDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailAddressDetail.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailAddressDetail.setFixedHeight(55);

            PdfPCell cellMailAddressDetailValue = new PdfPCell();
            cellMailAddressDetailValue.setPhrase(new Phrase(teacherQualification.getMailAddressDetail(), font1));
            cellMailAddressDetailValue.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMailAddressDetailValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellMailAddressDetailValue.setFixedHeight(55);
            cellMailAddressDetailValue.setColspan(2);

            table.addCell(cellBaseInfo);
            table.addCell(cellName);
            table.addCell(cellNameValue);
            table.addCell(cellIdCard);
            table.addCell(cellIdCardValue);
            table.addCell(cellSignNumber);
            table.addCell(cellSignNumberValue);
            table.addCell(cellType);
            table.addCell(cellTypeValue);
            table.addCell(cellMailInfo);
            table.addCell(cellMailName);
            table.addCell(cellMailNameValue);
            table.addCell(cellMailIdCard);
            table.addCell(cellMailIdCardValue);
            table.addCell(cellMailPhone);
            table.addCell(cellMailPhoneValue);
            table.addCell(cellMailAddress);
            table.addCell(cellMailAddressValue);
            table.addCell(cellMailAddressDetail);
            table.addCell(cellMailAddressDetailValue);
            document.add(table);

            document.close();
        } catch (Exception e) {
            map.put("isSuccess", false);
            map.put("message", e.getMessage());
            return JSON.toJSONString(map);
        }
        map.put("isSuccess", true);
        map.put("pdfName", tempName);
        return tempFileName;
    }



    public static HSSFWorkbook donloadExcel(List<TeacherQualificationEntity> list){
        String[] excelHeader = { "姓名","报名类型", "报名号","身份证号","手机号","地址"};
        HSSFWorkbook wb = new HSSFWorkbook();
        //创建HSSFSheet对象
        HSSFSheet sheet = wb.createSheet("关系表");
        HSSFRow row = sheet.createRow((int) 0);
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);

        for (int i = 0; i < excelHeader.length; i++) {
            HSSFCell cell = row.createCell(i);
            cell.setCellValue(excelHeader[i]);
            cell.setCellStyle(style);
            sheet.autoSizeColumn(i);
            //设置指定列的列宽，256 * 50这种写法是因为width参数单位是单个字符的256分之一
            sheet.setColumnWidth(cell.getColumnIndex(), 100 * 50);
        }

        for (int i = 0; i < list.size(); i++) {
            row = sheet.createRow(i + 1);
            TeacherQualificationEntity teacherQualificationEntity = list.get(i);
            row.createCell(0).setCellValue(teacherQualificationEntity.getMailName());
            Integer type = teacherQualificationEntity.getType();
            String lx = "";
            if(type==1){
                lx="幼儿园教师资格认定";
            }
            if(type==2){
                lx="小学教师资格认定";
            }
            if(type==3){
                lx="初级中学教师资格认定";
            }
            row.createCell(1).setCellValue(lx);
            row.createCell(2).setCellValue(teacherQualificationEntity.getSignNumber());
            row.createCell(3).setCellValue(teacherQualificationEntity.getIdCard());
            row.createCell(4).setCellValue(teacherQualificationEntity.getMailPhone());
            row.createCell(5).setCellValue(teacherQualificationEntity.getMailAddressDetail());
        }
        return wb;

    }


}
